<?php
    include "../function/functionPHP.php";
    include "../class/member.class.php";
        
    if($_POST["memID"]==""){
        $member=new member();
        if($member->availableUsername($_POST["user"])){
            $member->addMember($_POST);
        }else{
            ?>
<!DOCTYPE html>
<html class="ui-mobile">
    <head>
        <title>Cost Analysis</title>
        <meta charset="utf-8">
        <script type="text/javascript">
            alert("ชื่อผู้ใช้ระบบซ้ำ");
            location.replace('../?page=member/memberRegist&memID=<?=$_POST["memID"]?>');            
        </script>
    </head>
</html>
            <?php
            exit();
        }
    }else{
        $member=new member($_POST["memID"]);
        if($member->availableUsername($_POST["user"],$_POST["memID"])){
            $member->updateMember($_POST);
        }else{
            ?>
<!DOCTYPE html>
<html class="ui-mobile">
    <head>
        <title>Cost Analysis</title>
        <meta charset="utf-8">
        <script type="text/javascript">
            alert("ชื่อผู้ใช้ระบบซ้ำ");
            location.replace('../?page=member/memberRegist&memID=<?=$_POST["memID"]?>');            
        </script>
    </head>
</html>
            <?php
            exit();
        }
    }
    
    
?>
<!DOCTYPE html>
<html class="ui-mobile">
    <head>
        <title>Cost Analysis</title>
        <meta charset="utf-8">
        <script type="text/javascript">
            alert("ลงทะเบียนเรียบร้อย");
            <?php
                if(ofAuthenticated()){
                    ?>
            location.replace('../?page=member/memberList');
                    <?php
                }else{
                    ?>
            location.replace('../');
                    <?php
                }
            ?>
            
        </script>
    </head>
</html>